package y24.m4;

import java.util.Scanner;

public class Test10 {
    static class Triangle{
        private double b1;
        private double b2;
        private double b3;
        private double C;
        private double S;

        public Triangle(double b1, double b2, double b3) {
            this.b1 = b1;
            this.b2 = b2;
            this.b3 = b3;
        }

        public void setB1(double b1) {
            this.b1 = b1;
        }

        public void setB2(double b2) {
            this.b2 = b2;
        }

        public void setB3(double b3) {
            this.b3 = b3;
        }
        public boolean isTriangle(){
            return (b1 + b2 > b3) && (b2 + b3 > b1) && (b3 + b1 > b2);
        }
        public void setC(){
            this.C = b1 + b2 + b3;
        }
        public void setS(){
            double p = this.C / 2;
            this.S = Math.sqrt(p * (p - b1) * (p - b2) * (p - b3));
        }
    }
    static class Ladder{
        private double b4;
        private double b5;
        private double h;

        public Ladder(double b4, double b5, double h) {
            this.b4 = b4;
            this.b5 = b5;
            this.h = h;
        }

        public double setS(){
            return (b4 + b5) * h / 2;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入三角形的三边-->");
        Triangle triangle = getTriangle(scanner);
        System.out.println("三角形的周长为：" + triangle.C);
        System.out.println("三角形的面积为：" + triangle.S);
        System.out.print("请输入梯形的上底，下底和高-->");
        double x = scanner.nextDouble();
        double y = scanner.nextDouble();
        double h = scanner.nextDouble();
        Ladder ladder = new Ladder(x,y,h);
        System.out.println("这个梯形的面积为：" + ladder.setS());

    }

    private static Triangle getTriangle(Scanner scanner) {
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        double c = scanner.nextDouble();
        Triangle triangle = new Triangle(a,b,c);
        if (triangle.isTriangle()){
            triangle.setC();
            triangle.setS();
            return triangle;
        }else {
            System.out.print("这不是一个三角形请重新输入三角形的三边-->");
            return getTriangle(scanner);
        }
    }
}